from django.shortcuts import render,get_object_or_404
from django.http import HttpResponse
from .models import *
import markdown


# Create your views here.
def index(request):
    post_lsit = Post.objects.all().order_by('-created_time')
    content = {'title':'首页',
               'welcome':'欢迎来到播客首页',
               'post_list':post_lsit}

    return render(request,'blog/index.html',content)

def detail(request,pid):

    #  markdown 引入图片的格式为![图片说明](图片链接)
    post = get_object_or_404(Post,id=pid)
    post.body = markdown.markdown(post.body,
                                  extensions=[
                                      'markdown.extensions.extra',
                                      'markdown.extensions.codehilite',
                                      'markdown.extensions.toc',
                                  ])
    return render(request,'blog/detail.html',context={'post':post})
